package SURF;
import OpenCV.cv;
import OpenCV.cv.IplImage;
import SIFT.util.FloatArray2D;
import SURF.util.Params;
import SURF.util.IntegralImage;
import SURF.util.InterestPoint;
import ij.IJ;
import java.util.List;

import com.sun.jna.Pointer;




// Designed according to the "PlugIn Design Guidelines" 
// http://pacific.mpi-cbg.de/wiki/index.php/PlugIn_Design_Guidelines

public class Surf {
	public static String title = "SURF: Compare Images";

        
        
	public static void run(FloatArray2D im1) {
		
		Params p1 = new Params();
		Params p2 = new Params(p1);
		
		IntegralImage intImg1 = new IntegralImage(im1, true);
		
		List<InterestPoint> ipts1 = IJFacade.detectAndDescribeInterestPoints(intImg1, p1);

                if (ipts1.isEmpty()) {
			IJ.showMessage(title, "No interest points found.");
			return;
		}
                IJ.showMessage(ipts1.size() + " Interest Points");
              			
	}

	
        public static void main(String argv[])
        {
            cv.loadHighgui();
            cv.loadCv();
            cv.loadCxcore();

            FloatArray2D image1;
            Pointer img = cv.LoadImage("Joints1.bmp", 0);
            IplImage labD = new IplImage(img);
            byte[] bfl = HGR.Core.Pointer2Byte(img);
            //imp1.data = new float[bfl.length];
            image1 = new FloatArray2D(labD.width, labD.height);
            for(int k=0; k<bfl.length; k++){
            if(bfl[k]<0)
                image1.data[k] = bfl[k] & 0xFF;
            else
                image1.data[k] = bfl[k];
            }


            //Surf hh = new Surf();

            long begin = System.currentTimeMillis();
            Surf.run(image1);
            long end = System.currentTimeMillis();
            System.out.println("Tiempo "+ (end - begin));

            Save_Interest_Points_To_File FilePoints = new Save_Interest_Points_To_File();
            FilePoints.SurfFile(0,"xx");
        }

}
